/**
 *  各类工具类
 *  1. Ajax 异步请求
 *  2. 表单数据遍历
 *  3. FormatDate() 日期适配
 */
///Ajax 工具方法
var AjaxOpt = function(){
	var opt = {};
	
	opt.ajax = function(type, url, data, headers, context, callback) {
        $.ajax({
            type: type,
            url: url,
            data: JSON.stringify(data),
            headers: headers,
            context: context
        }).done(callback);
    };
	
    return opt;
}();

///读取表单数据，构造对象
var formOpt = function(){
	var obj = {};
	obj.formToObject = function(formObj){
		var object = {};
		var t = $(formObj).serializeArray();
		$.each(t,function(){
			if(this.name == "sal"){
				object[this.name] = Number(this.value);
			}else if(this.name == "birth"){
				object[this.name] = this.value;
			}else if(this.name == "sex"){
				if(this.value=="true"){
					object[this.name] = true;
				}else{
					object[this.name] = false;
				}
			}else{
				object[this.name] = this.value;
			}
		});
		//alert(JSON.stringify(object));
		return object;
	}
	return obj;
}();

///生日format
function FormatDate (strTime) {
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}

